<?php
	class User extends CI_Controller{
		function __construct(){
			parent::__construct();
			$this->load->model('user/user_model');
			$this->load->model('user/setting_model');
			$this->setting=$this->setting_model->getSetting();
			$this->user=$this->user_model->get_user();
			//config
			if(!defined('TIPASK_ROOT')){define('TIPASK_ROOT', dirname(__FILE__));}
			if(!defined('SITE_URL'))define('SITE_URL',base_url().'tipask/');
			if(!defined('DY_URL'))define('DY_URL',base_url()."index.php/");
			if(!defined('DB_HOST'))define('DB_HOST', '127.0.0.1');
			if(!defined('DB_USER'))define('DB_USER', 'shibei');
			if(!defined('DB_PW'))define('DB_PW', 'dongyueweb');
			if(!defined('DB_NAME'))define('DB_NAME', 'shibei');
			if(!defined('DB_CHARSET'))define('DB_CHARSET', 'utf8');
			if(!defined('DB_TABLEPRE'))define('DB_TABLEPRE', 'ask_');
			if(!defined('DB_CONNECT'))define('DB_CONNECT', 0);
			if(!defined('TIPASK_CHARSET'))define('TIPASK_CHARSET', 'UTF-8');
			if(!defined('TIPASK_VERSION'))define('TIPASK_VERSION', '1.3Beta');
			if(!defined('TIPASK_RELEASE'))define('TIPASK_RELEASE', '20110214');
			global $starttime,$querynum;$mtime = explode(' ', microtime());$runtime=number_format($mtime['1'] + $mtime['0'] - $starttime,6);

		}
		//我的上传页面
		function myshare($offset=0){
			
			//$this->load->model('user/user_model');
			$uid = $this->user_model->get_uid();
			$historylist= $this->user_model->get_upload_history($uid,8,$offset);
			$this->load->model('share/file');
			$this->load->library('pagination');
			$this->load->model('share/file');
			$config['uri_segment'] = 4;
			$config['base_url'] = site_url('user/user/myshare');
			$config['total_rows'] =$this->file->get_upload_times($uid);
			//echo sizeof($historylist);
		    $config['per_page'] = '8';
			$this->pagination->initialize($config); 
			$data=array(
				'historylist'=>$historylist,
				'regular'=>' ',
				'user'=>$this->user,
				'setting'=>$this->setting
			);
            /* modified by scott shen */
            $this->parser->parse('header',array('title'=>'我的分享'));
            /* end */
			$data['hintNoshare']='对不起，您暂时还没有分享哦~~快去分享吧~~';
			$this->load->view('user/user_myshare',$data);
			$this->load->view('footer');
		}

		function space_share($uid,$offset=0){
			$historylist= $this->user_model->get_upload_history($uid,8,$offset);
			$this->load->model('share/file');
			$this->load->library('pagination');
			$this->load->model('share/file');
			$config['uri_segment'] = 5;
			$config['base_url'] = site_url('user/user/space_share/'.$uid);
			$config['total_rows'] =$this->file->get_upload_times($uid);
			//echo sizeof($historylist);
		    $config['per_page'] = '8';
			$this->pagination->initialize($config); 
			$data=array(
				'historylist'=>$historylist,
				'regular'=>' ',
				'user'=>$this->user_model->get_user($uid),
				'setting'=>$this->setting
			);
            /* modified by scott shen */
            $this->parser->parse('header',array('title'=>'TA的分享'));
            /* end */
			$data['hintNoshare']='TA暂时还没有分享哦~~';
			$this->load->view('user/user_space_share',$data);
			$this->load->view('footer');
		}
		function myrecall($offset=0){
			$uid = $this->user_model->get_uid();
			$this->load->model('recall/recall_paper_model');
			$historylist= $this->recall_paper_model->read_recall_paper($uid,8,$offset);
			$this->load->library('pagination');
			//$this->load->model('share/file');
			$config['uri_segment'] = 4;
			$config['base_url'] = site_url('user/user/myrecall');
			$config['total_rows'] =$this->recall_paper_model->get_recall_times($uid);
		    $config['per_page'] = '8';
			$this->pagination->initialize($config); 
			$data=array(
				'historylist'=>$historylist,
				'regular'=>' ',
				'user'=>$this->user,
				'setting'=>$this->setting
			);
            /* modified by scott shen */
            $this->parser->parse('header',array('title'=>'我的回忆'));
            /* end */
			$data['hintNorecall']='对不起，您暂时还没有回忆哦~~快去回忆吧~~';
			$this->load->view('user/user_myrecall',$data);
			$this->load->view('footer');			
		}

			function space_recall($uid,$offset=0){
			$this->load->model('recall/recall_paper_model');
			$historylist= $this->recall_paper_model->read_recall_paper($uid,8,$offset);
			$this->load->library('pagination');
			//$this->load->model('share/file');
			$config['uri_segment'] = '5';
			$config['base_url'] = site_url('user/user/space_recall/'.$uid);
			$config['total_rows'] =$this->recall_paper_model->get_recall_times($uid);
		    $config['per_page'] = '8';
			$this->pagination->initialize($config); 
			$data=array(
				'historylist'=>$historylist,
				'regular'=>' ',
				'user'=>$this->user_model->get_user($uid),
				'setting'=>$this->setting
			);

            /* modified by scott shen */
            $this->parser->parse('header',array('title'=>'TA的回忆'));
            /* end */
			$data['hintNorecall']='TA暂时还没有回忆哦~~';
			$this->load->view('user/user_space_recall',$data);
			$this->load->view('footer');			
		}
			
		function refreshrp(){
			//$this->load->model('user/user_model');
			$this->user_model->refresh_rp(3,20000);
		}	
		function test(){
			$this->load->library("global_func");
			//echo realpath("http://localhost:8080/shibei/index.php");
			
			echo $this->global_func->get_avatar_dir(2);
			print_r($_SERVER);
			//print_r($_SERVER);
		}
		function index(){
			$this->load->model('recall/recall_paper_model');
			$this->load->model('recall/recall_problem_model');
			$this->load->model('share/file');
			$top['title']=$this->recall_paper_model->top_sth(10,'title');
			$top['j_id']=$this->recall_paper_model->top_sth(10,'j_id');
			$top['hit_cnt']=$this->recall_paper_model->top_sth(10,'hit_cnt');
			$top['u_id']=$this->recall_paper_model->top_sth(10,'u_id');
			$i=0;
			foreach($top['u_id'] as $uid){
				$top['username'][$i]=$this->user_model->get_user_name($uid);
				$i++;
			}
			$top['tags']=$this->recall_paper_model->top_sth(10,'tags');
			$top['problem']=$this->recall_problem_model->read_recall_problem(-1,5,0,"creat_time","desc");
			$rank=$this->file->get_rank();
			$alluserlist=$this->user_model->list_by_credit(0,$this->setting['list_indexallscore']);
			$weekuserlist=$this->user_model->list_by_credit(1,$this->setting['list_indexallscore']);
			$question=$this->user_model->get_question();
			$data=array(
				'title'=>'学海拾贝',
				'regular'=>'index/user',
				'top'=>$top,
				'rank'=>$rank,
				'setting'=>$this->setting,
				'user'=>$this->user,
				'alluserlist'=>$alluserlist,
				'weekuserlist'=>$weekuserlist,
				'question'=>$question
			);
			$this->load->view('header',array('title'=>'学海拾贝'));
			$this->load->view('user/user_rightcolumn',$data);
			$this->load->view('footer',$data);
			
		}
	}



